<html>

<head>
<title>Flyweight Pattern</title>
<link rel="stylesheet" type="text/css" href="../../../style.css">
</head>

<body>

<h1>Flyweight</h1>
<ul>
  <li><a href="#Purpose">Purpose)</a></li>
  <li><a href="#Structure">Structure)</a></li>
  <li><a href="#Applications">Applications)</a></li>
  <li><a href="#Consequences">Consequences)</a></li>
</ul>
<h2><a name="Purpose">Purpose</a></h2>
<ul type="square">
  <li>Use sharing to support large numbers of fine-grained objects efficiently.</li>
</ul>
<h2><a name="Structure">Structure</a></h2>
<p>&nbsp;
<img border="0" src="Flyweight_Model1.gif" width="609" height="348"></p>
<ul type="square">
  <li><b>Flyweight :</b> declares an interface through which flyweights can 
	receive and act on extrinsic state.</li>
  <li><b>ConcreteFlyweight :</b> implements the Flyweight interface and adds 
	storage for intrinsic state, if any. A ConcreteFlyweight object must be 
	sharable. Any state it stores must be intrinsic; that is, it must be 
	independent of the ConcreteFlyweight object's context.</li>
  <li><b>UnsharedConcreteFlyweight :</b> not all Flyweight subclasses need to be 
	shared. The Flyweight interface enables sharing; it doesn't enforce it. It's 
	common for UnsharedConcreteFlyweight objects to have ConcreteFlyweight 
	objects as children at some level in the flyweight object structure (as the 
	Row and Column classes have).</li>
  <li><b>FlyweightFactory :</b> creates and manages flyweight objects. ensures 
	that flyweights are shared properly. When a client requests a flyweight, the 
	FlyweightFactory object supplies an existing instance or creates one, if 
	none exists.</li>
  <li><b>Client :</b> maintains a reference to flyweight(s). computes or stores 
	the extrinsic state of flyweight(s).</li>
</ul>
<h2><a name="Applications">Applications</a></h2>
<ul type="square">
  <li>An application uses a large number of objects.</li>
  <li>Storage costs are high because of the sheer quantity of objects.</li>
  <li>Most object state can be made extrinsic.</li>
  <li>Many groups of objects may be replaced by relatively few shared objects 
	once extrinsic state is removed.</li>
  <li>The application doesn't depend on object identity. Since flyweight objects 
	may be shared, identity tests will return true for conceptually distinct 
	objects.</li>
</ul>
<h2><a name="Consequences">Consequences</a></h2>
<ul type="square">
  <li>the reduction in the total number of instances that comes from sharing</li>
	<li>the amount of intrinsic state per object</li>
  <li>whether extrinsic state is computed or stored.</li>
</ul>

</body>

</html>
